package com.yuexunit.operationman.nbsy.module.plant.ui;

import android.view.View;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.nurse.Bean.NurseBean;
import com.yuexunit.operationman.nbsy.widget.SetBPDialog;
import com.yuexunit.operationman.nbsy.widget.SetHRDialog;
import com.yuexunit.operationman.nbsy.widget.SetOSDialog;

import org.kymjs.kjframe.KJActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/12 0012.
 */

public class Act_Flax_Meter extends KJActivity {
    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.preoperative_rate)
    TextView preoperativeRate;
    @Bind(R.id.preoperative_bp)
    TextView preoperativeBp;
    @Bind(R.id.preoperative_saturation)
    TextView preoperativeSaturation;
    @Bind(R.id.rate_10)
    TextView rate10;
    @Bind(R.id.bp_10)
    TextView bp10;
    @Bind(R.id.saturation_10)
    TextView saturation10;
    @Bind(R.id.rate_20)
    TextView rate20;
    @Bind(R.id.bp_20)
    TextView bp20;
    @Bind(R.id.saturation_20)
    TextView saturation20;
    @Bind(R.id.rate_30)
    TextView rate30;
    @Bind(R.id.bp_30)
    TextView bp30;
    @Bind(R.id.saturation_30)
    TextView saturation30;
    @Bind(R.id.rate_40)
    TextView rate40;
    @Bind(R.id.bp_40)
    TextView bp40;
    @Bind(R.id.saturation_40)
    TextView saturation40;
    @Bind(R.id.rate_50)
    TextView rate50;
    @Bind(R.id.bp_50)
    TextView bp50;
    @Bind(R.id.saturation_50)
    TextView saturation50;
    @Bind(R.id.rate_60)
    TextView rate60;
    @Bind(R.id.bp_60)
    TextView bp60;
    @Bind(R.id.saturation_60)
    TextView saturation60;
    @Bind(R.id.rate_70)
    TextView rate70;
    @Bind(R.id.bp_70)
    TextView bp70;
    @Bind(R.id.saturation_70)
    TextView saturation70;
    @Bind(R.id.rate_80)
    TextView rate80;
    @Bind(R.id.bp_80)
    TextView bp80;
    @Bind(R.id.saturation_80)
    TextView saturation80;
    @Bind(R.id.rate_90)
    TextView rate90;
    @Bind(R.id.bp_90)
    TextView bp90;
    @Bind(R.id.saturation_90)
    TextView saturation90;
    @Bind(R.id.rate_100)
    TextView rate100;
    @Bind(R.id.bp_100)
    TextView bp100;
    @Bind(R.id.saturation_100)
    TextView saturation100;
    @Bind(R.id.rate_110)
    TextView rate110;
    @Bind(R.id.bp_110)
    TextView bp110;
    @Bind(R.id.saturation_110)
    TextView saturation110;
    @Bind(R.id.rate_120)
    TextView rate120;
    @Bind(R.id.bp_120)
    TextView bp120;
    @Bind(R.id.saturation_120)
    TextView saturation120;
    @Bind(R.id.rate_130)
    TextView rate130;
    @Bind(R.id.bp_130)
    TextView bp130;
    @Bind(R.id.saturation_130)
    TextView saturation130;
    @Bind(R.id.rate_140)
    TextView rate140;
    @Bind(R.id.bp_140)
    TextView bp140;
    @Bind(R.id.saturation_140)
    TextView saturation140;
    @Bind(R.id.rate_150)
    TextView rate150;
    @Bind(R.id.bp_150)
    TextView bp150;
    @Bind(R.id.saturation_150)
    TextView saturation150;
    @Bind(R.id.postoperation_rate)
    TextView postoperationRate;
    @Bind(R.id.postoperation_bp)
    TextView postoperationBp;
    @Bind(R.id.postoperation_saturation)
    TextView postoperationSaturation;

    SetBPDialog setBPDialog;
    SetHRDialog setHRDialog;
    SetOSDialog setOSDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_flax_meter);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        setContent();
        setBPDialog = new SetBPDialog(aty);
        setHRDialog = new SetHRDialog(aty);
        setOSDialog = new SetOSDialog(aty);
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientName());
        if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.NURSEBEAN.getObject().getNursing().getInHospitalNo());
        tvPatientDisease.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPreoperativeDiagnosis());
    }

    private void setContent() {
        for (NurseBean.ObjectEntity.NursingItemListEntity p : AppConfig.NURSEBEAN.getObject().getNursingItemList()) {
            switch (p.getItemCode()) {
                case "SP_MZ_HR":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        preoperativeRate.setText(skin[0]);
                        rate10.setText(skin[1]);
                        rate20.setText(skin[2]);
                        rate30.setText(skin[3]);
                        rate40.setText(skin[4]);
                        rate50.setText(skin[5]);
                        rate60.setText(skin[6]);
                        rate70.setText(skin[7]);
                        rate80.setText(skin[8]);
                        rate90.setText(skin[9]);
                        rate100.setText(skin[10]);
                        rate110.setText(skin[11]);
                        rate120.setText(skin[12]);
                        rate130.setText(skin[13]);
                        rate140.setText(skin[14]);
                        rate150.setText(skin[15]);
                        postoperationRate.setText(skin[16]);
                    }
                    break;
                case "SP_MZ_BP":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        preoperativeBp.setText(skin[0]);
                        bp10.setText(skin[1]);
                        bp20.setText(skin[2]);
                        bp30.setText(skin[3]);
                        bp40.setText(skin[4]);
                        bp50.setText(skin[5]);
                        bp60.setText(skin[6]);
                        bp70.setText(skin[7]);
                        bp80.setText(skin[8]);
                        bp90.setText(skin[9]);
                        bp100.setText(skin[10]);
                        bp110.setText(skin[11]);
                        bp120.setText(skin[12]);
                        bp130.setText(skin[13]);
                        bp140.setText(skin[14]);
                        bp150.setText(skin[15]);
                        postoperationBp.setText(skin[16]);
                    }
                    break;
                case "SP_MZ_OS":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        preoperativeSaturation.setText(skin[0]);
                        saturation10.setText(skin[1]);
                        saturation20.setText(skin[2]);
                        saturation30.setText(skin[3]);
                        saturation40.setText(skin[4]);
                        saturation50.setText(skin[5]);
                        saturation60.setText(skin[6]);
                        saturation70.setText(skin[7]);
                        saturation80.setText(skin[8]);
                        saturation90.setText(skin[9]);
                        saturation100.setText(skin[10]);
                        saturation110.setText(skin[11]);
                        saturation120.setText(skin[12]);
                        saturation130.setText(skin[13]);
                        saturation140.setText(skin[14]);
                        saturation150.setText(skin[15]);
                        postoperationSaturation.setText(skin[16]);
                    }
                    break;
            }
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.tv_submit, R.id.preoperative_rate,
            R.id.preoperative_bp, R.id.preoperative_saturation,
            R.id.rate_10, R.id.bp_10, R.id.saturation_10, R.id.rate_20, R.id.bp_20, R.id.saturation_20,
            R.id.rate_30, R.id.bp_30, R.id.saturation_30, R.id.rate_40, R.id.bp_40, R.id.saturation_40,
            R.id.rate_50, R.id.bp_50, R.id.saturation_50, R.id.rate_60, R.id.bp_60, R.id.saturation_60,
            R.id.rate_70, R.id.bp_70, R.id.saturation_70, R.id.rate_80, R.id.bp_80, R.id.saturation_80,
            R.id.rate_90, R.id.bp_90, R.id.saturation_90, R.id.rate_100, R.id.bp_100, R.id.saturation_100,
            R.id.rate_110, R.id.bp_110, R.id.saturation_110, R.id.rate_120, R.id.bp_120, R.id.saturation_120,
            R.id.rate_130, R.id.bp_130, R.id.saturation_130, R.id.rate_140, R.id.bp_140, R.id.saturation_140,
            R.id.rate_150, R.id.bp_150, R.id.saturation_150,
            R.id.postoperation_rate, R.id.postoperation_bp, R.id.postoperation_saturation})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.tv_submit:
                insertContent();
                finish();
                break;
            case R.id.preoperative_rate:
                sethr(preoperativeRate,"术前");
                break;
            case R.id.preoperative_bp:
                setbp(preoperativeBp, "术前");
                break;
            case R.id.preoperative_saturation:
                setos(preoperativeSaturation, "术前");
                break;
            case R.id.rate_10:
                sethr(rate10,"10");
                break;
            case R.id.bp_10:
                setbp(bp10,"10");
                break;
            case R.id.saturation_10:
                setos(saturation10,"10");
                break;
            case R.id.rate_20:
                sethr(rate20,"20");
                break;
            case R.id.bp_20:
                setbp(bp20,"20");
                break;
            case R.id.saturation_20:
                setos(saturation20,"20");
                break;
            case R.id.rate_30:
                sethr(rate30,"30");
                break;
            case R.id.bp_30:
                setbp(bp30,"30");
                break;
            case R.id.saturation_30:
                setos(saturation30,"30");
                break;
            case R.id.rate_40:
                sethr(rate40,"40");
                break;
            case R.id.bp_40:
                setbp(bp40,"40");
                break;
            case R.id.saturation_40:
                setos(saturation40,"40");
                break;
            case R.id.rate_50:
                sethr(rate50,"50");
                break;
            case R.id.bp_50:
                setbp(bp50,"50");
                break;
            case R.id.saturation_50:
                setos(saturation50,"50");
                break;
            case R.id.rate_60:
                sethr(rate60,"60");
                break;
            case R.id.bp_60:
                setbp(bp60,"60");
                break;
            case R.id.saturation_60:
                setos(saturation60,"60");
                break;
            case R.id.rate_70:
                sethr(rate70,"70");
                break;
            case R.id.bp_70:
                setbp(bp70,"70");
                break;
            case R.id.saturation_70:
                setos(saturation70,"70");
                break;
            case R.id.rate_80:
                sethr(rate80,"80");
                break;
            case R.id.bp_80:
                setbp(bp80,"80");
                break;
            case R.id.saturation_80:
                setos(saturation80,"80");
                break;
            case R.id.rate_90:
                sethr(rate90,"90");
                break;
            case R.id.bp_90:
                setbp(bp90,"90");
                break;
            case R.id.saturation_90:
                setos(saturation90,"90");
                break;
            case R.id.rate_100:
                sethr(rate100,"100");
                break;
            case R.id.bp_100:
                setbp(bp100,"100");
                break;
            case R.id.saturation_100:
                setos(saturation100,"100");
                break;
            case R.id.rate_110:
                sethr(rate110,"110");
                break;
            case R.id.bp_110:
                setbp(bp110,"110");
                break;
            case R.id.saturation_110:
                setos(saturation110,"110");
                break;
            case R.id.rate_120:
                sethr(rate120,"120");
                break;
            case R.id.bp_120:
                setbp(bp120,"120");
                break;
            case R.id.saturation_120:
                setos(saturation120,"120");
                break;
            case R.id.rate_130:
                sethr(rate130,"130");
                break;
            case R.id.bp_130:
                setbp(bp130,"130");
                break;
            case R.id.saturation_130:
                setos(saturation130,"130");
                break;
            case R.id.rate_140:
                sethr(rate140,"140");
                break;
            case R.id.bp_140:
                setbp(bp140,"140");
                break;
            case R.id.saturation_140:
                setos(saturation140,"140");
                break;
            case R.id.rate_150:
                sethr(rate150,"150");
                break;
            case R.id.bp_150:
                setbp(bp150,"150");
                break;
            case R.id.saturation_150:
                setos(saturation150,"150");
                break;
            case R.id.postoperation_rate:
                sethr(postoperationRate,"术后");
                break;
            case R.id.postoperation_bp:
                setbp(postoperationBp,"术后");
                break;
            case R.id.postoperation_saturation:
                setos(postoperationSaturation,"术后");
                break;
        }
    }

    private void insertContent() {
        for (int i = 0; i < AppConfig.NURSEBEAN.getObject().getNursingItemList().size(); i++) {
            switch (AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).getItemCode()) {
                case "SP_MZ_HR":
                    AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(preoperativeRate.getText().toString()
                    +";" +rate10.getText().toString()+";" +rate20.getText().toString()+";" +rate30.getText().toString()
                    +";" +rate40.getText().toString()+";" +rate50.getText().toString()+";" +rate60.getText().toString()
                    +";" +rate70.getText().toString()+";" +rate80.getText().toString()+";" +rate90.getText().toString()
                    +";" +rate100.getText().toString()+";" +rate110.getText().toString()+";" +rate120.getText().toString()
                    +";" +rate130.getText().toString()+";" +rate140.getText().toString()+";" +rate150.getText().toString()
                    +";"+postoperationRate.getText().toString());
                    break;
                case "SP_MZ_BP":
                    AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(preoperativeBp.getText().toString()
                            +";" +bp10.getText().toString()+";" +bp20.getText().toString()+";" +bp30.getText().toString()
                            +";" +bp40.getText().toString()+";" +bp50.getText().toString()+";" +bp60.getText().toString()
                            +";" +bp70.getText().toString()+";" +bp80.getText().toString()+";" +bp90.getText().toString()
                            +";" +bp100.getText().toString()+";" +bp110.getText().toString()+";" +bp120.getText().toString()
                            +";" +bp130.getText().toString()+";" +bp140.getText().toString()+";" +bp150.getText().toString()
                            +";"+postoperationBp.getText().toString());
                    break;
                case "SP_MZ_OS":
                    AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(preoperativeSaturation.getText().toString()
                            +";" +saturation10.getText().toString()+";" +saturation20.getText().toString()+";" +saturation30.getText().toString()
                            +";" +saturation40.getText().toString()+";" +saturation50.getText().toString()+";" +saturation60.getText().toString()
                            +";" +saturation70.getText().toString()+";" +saturation80.getText().toString()+";" +saturation90.getText().toString()
                            +";" +saturation100.getText().toString()+";" +saturation110.getText().toString()+";" +saturation120.getText().toString()
                            +";" +saturation130.getText().toString()+";" +saturation140.getText().toString()+";" +saturation150.getText().toString()
                            +";"+postoperationSaturation.getText().toString());
                    break;
            }
        }
    }

    private void setbp(final TextView tv,String time)
    {
        setBPDialog.builder();
        setBPDialog.show();
        setBPDialog.setTxt("时间:"+time);
        setBPDialog.setCallBack(new SetBPDialog.ICallBack() {
            @Override
            public void callback(String date) {
                tv.setText(date);
                setBPDialog.dismiss();
            }
        });
    }

    private void sethr(final TextView tv,String time)
    {
        setHRDialog.builder();
        setHRDialog.show();
        setHRDialog.setTxt("时间:"+time);
        setHRDialog.setCallBack(new SetHRDialog.ICallBack() {
            @Override
            public void callback(String date) {
                tv.setText(date);
                setHRDialog.dismiss();
            }
        });
    }

    private void setos(final TextView tv,String time)
    {
        setOSDialog.builder();
        setOSDialog.show();
        setOSDialog.setTxt("时间:"+time);
        setOSDialog.setCallBack(new SetOSDialog.ICallBack() {
            @Override
            public void callback(String date) {
                tv.setText(date);
                setOSDialog.dismiss();
            }
        });
    }
}
